<extend name="layout/edit" />

<block name="HEADER">

</block>

<block name="CONTENT">
    <control:form id="form"/>

</block>

<block name="FOOTER">
   <script type="text/javascript">
    var  page=(function(ns){
    	
		ns.init = function(){
			
			if(__mode==3){
				$("#btnSave,#btnAdd").hide();
			}

		    if(form.getValue('role_id')!=2){
                form.setReadonly('good_name',false,false);   //不是必填,不可编辑
            }

		}

        ns.addIndex = 0;

        //增加行。
        ns.addRow=function(){
                form.$grids['editagentGrid'].addRow([{
                    recommended_level: form.getValue('recommended_level'),
                    user_level_id: form.getValue('user_level_id'),
                    stand_peoples: 0,
                    stand_reward: 0,
                    no_stand_reward: 0
            }]);

        }

        //代理增加显示
        ns.add = function(){

             var filter = {
                    url: $.getModule('details'),
                    mode:1
                }
            $.openIframe(filter, "新增",['500px', '520px']);

        }

        //选择商品
        ns.selectGoods = function(){
            var filter = {
                url:"modules/common/selectGoods",
                mode:1
            }
            $.openIframe(filter,"选择商品",['600px', '480px']);
        }

        //回调并进行赋值给
        ns.selectGoodsCallback = function(ids,data){
            form.setValue('good_name',data[0]['name']);
            form.setValue('goods_id',data[0]['id']);
        }


        //保存,
        ns.save=function(){
		    var data = form.getData();
		    if(!data) return false;

            //单表保存
    		form.save(1).then(function(res){
                //一个接口保存多个表。获取了数据，然后进行保存。data:JSON.stringify(
                $.ajaxs("/admin/v1/user_level/edit",{
                    level_id:form.getValue('user_level_id'),
                    data:JSON.stringify(form.$grids['editagentGrid'].getRows())
                }).then(function(res){
                    form.opener.$.toast(1,'保存成功！');
                    form.opener.grid.load();
                    // $.setRequest({'mode':2,oid:res.data})
                    $.close();
                })
            	form.opener.grid.load();
            });
        }

         ns.deleteRow = function(){
            $.confirm("确定删除？",function(index){
                form.$grids['editagentGrid'].deleteRow();
                layer.close(index);
            });
        }
        
        return ns;
    }({}));
    
    $(function(){ page.init(); });
   </script>
</block>



